﻿' ******************************************************************************
' ** 
' **  Yahoo! Managed
' **  Written by Marius Häusler 2011
' **  It would be pleasant, if you contact me when you are using this code.
' **  Contact: YahooFinanceManaged@gmail.com
' **  Project Home: http://code.google.com/p/yahoo-finance-managed/
' **  
' ******************************************************************************
' **  
' **  Copyright 2011 Marius Häusler
' **  
' **  Licensed under the Apache License, Version 2.0 (the "License");
' **  you may not use this file except in compliance with the License.
' **  You may obtain a copy of the License at
' **  
' **    http://www.apache.org/licenses/LICENSE-2.0
' **  
' **  Unless required by applicable law or agreed to in writing, software
' **  distributed under the License is distributed on an "AS IS" BASIS,
' **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' **  See the License for the specific language governing permissions and
' **  limitations under the License.
' ** 
' ******************************************************************************


Namespace YahooManaged.Finance

    ''' <summary>
    ''' Stores informations of quote options.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class QuoteOptionData
        Private mValues(4) As Double

        ''' <summary>
        ''' The basic parts of new option symbol are: Root symbol + Expiration Year(yy)+ Expiration Month(mm)+ Expiration Day(dd) + Call/Put Indicator (C or P) + Strike price
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Symbol() As String
        ''' <summary>
        ''' Call/Put Indicator
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Type() As QuoteOptionType
        ''' <summary>
        '''  The stated price per share for which underlying stock can be purchased (in the case of a call) or sold (in the case of a put) by the option holder upon exercise of the option contract.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property StrikePrice() As Double
        ''' <summary>
        ''' The price of the last trade made for option contract.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LastPrice() As Double
        ''' <summary>
        ''' The change in price for the day. This is the difference between the last trade and the previous day's closing price (Prev Close). The change is reported as "0" if the option hasn't traded today.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Change() As Double
        ''' <summary>
        ''' The Bid price is the price you get if you were to write (sell) an option.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Bid() As Double
        ''' <summary>
        ''' The Ask price is the price you have to pay to purchase an option.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Ask() As Double
        ''' <summary>
        ''' The volume indicates the number of option contracts that have traded for the current day.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Volume() As Integer
        ''' <summary>
        ''' The total number of derivative contracts traded that have not yet been liquidated either by an offsetting derivative transaction or by delivery.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property OpenInterest() As Integer

        ''' <summary>
        ''' Default constructor
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
        End Sub
        Friend Sub New(ByVal symb As String, ByVal typ As QuoteOptionType, ByVal strike As Double, ByVal last As Double, ByVal cng As Double, ByVal b As Double, ByVal a As Double, ByVal vol As Integer, ByVal interest As Integer)
            Me.Symbol = symb
            Me.Type = typ
            Me.StrikePrice = strike
            Me.LastPrice = last
            Me.Change = cng
            Me.Bid = b
            Me.Ask = a
            Me.Volume = vol
            Me.OpenInterest = interest
        End Sub

        Public Overrides Function ToString() As String
            Return Me.Symbol
        End Function

    End Class



    Public Class QuoteOptionDataChain
        Implements ISettableID
        Implements IEnumerable(Of QuoteOptionData)

        Private mID As String = String.Empty
        Private mExpirationDate As Date
        Private mItems As New List(Of QuoteOptionData)


        Public ReadOnly Property ID() As String Implements IID.ID
            Get
                Return mID
            End Get
        End Property
        Public ReadOnly Property ExpirationDate As Date
            Get
                Return mExpirationDate
            End Get
        End Property
        Public Sub SetID(ByVal id As String) Implements ISettableID.SetID
            mID = id
        End Sub

        Default Public Property ItemAt(ByVal index As Integer) As QuoteOptionData
            Get
                Return mItems(index)
            End Get
            Set(ByVal value As QuoteOptionData)
                mItems(index) = value
            End Set
        End Property

        Public ReadOnly Property Items() As List(Of QuoteOptionData)
            Get
                Return mItems
            End Get
        End Property
        Public ReadOnly Property Count() As Integer
            Get
                Return mItems.Count
            End Get
        End Property

        Public Sub New()
        End Sub
        Public Sub New(ByVal id As String)
            mID = id
        End Sub
        Public Sub New(ByVal items As IEnumerable(Of QuoteOptionData))
            mItems = New List(Of QuoteOptionData)(items)
        End Sub
        Public Sub New(ByVal id As String, ByVal expirationDate As Date, ByVal items As IEnumerable(Of QuoteOptionData))
            Me.New(items)
            mID = id
            mExpirationDate = expirationDate
        End Sub

        Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of QuoteOptionData) Implements System.Collections.Generic.IEnumerable(Of QuoteOptionData).GetEnumerator
            Return mItems.GetEnumerator
        End Function
        Public Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
            Return mItems.GetEnumerator
        End Function

    End Class

End Namespace